package servlet;

import dao.MajorDao;
import pojo.Major;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/showAllMajorsServlet")
public class ShowAllMajorsServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //定义所有专业的集合
       List<Major> allMajors=new ArrayList<>();
        try {
            allMajors=MajorDao.findAllMajors();
        } catch (Exception e) {
            e.printStackTrace();
        }
        HttpSession session=request.getSession();
        session.setAttribute("allMajors",allMajors );
        //3. 重定向到showAllMajors.jsp
        response.sendRedirect("/lab08/showAllMajors.jsp");
    }
}
